<?php 
$appid = 98;
$num = mt_rand(3,5);
$sql = "select id from tttj.userinfo where regtype=2 order by rand() limit $num";
$robots = exec_db($sql);

while ($row = mysqli_fetch_assoc($robots))
{
	$time = time();
	$robotid = $row['id'];
	$sql = "select id from tttj.goods where tuan=1 and dstatus=1 and tuan_start<=$time and tuan_end>$time order by rand() limit 1";
	$goodsinfo = getonerecord($sql);
	$goodsid = $goodsinfo['id'];
	$etime = $time + 3600*24*3;
	$sql = "insert into tttj.tuan (uid,goods_id,num,ontime,stime,etime,dstatus,appid) values ($robotid,$goodsid,1,$time,$time,$etime,1,$appid)";
	exec_db($sql);
	$waittime = rand(5,100);
	sleep($waittime);
}	

?>